//
// Created by mio on 25-5-24.
//

#include "VideoCapture.h"

VideoCapture::VideoCapture()
    : stop_flag_(false),
      is_initialized_(false),
      width_(0),
      height_(0),
      target_framerate_(30), // 默认目标帧率 30 FPS
      current_fps_count_(0)
{
    // FPS 计时器初始化通常在 Init 或 run 开始时进行更合适
    last_fps_log_time_ = std::chrono::steady_clock::now(); // 可以在构造函数或Init中初始化
}

void VideoCapture::LogFPS()
{
    current_fps_count_++;
    auto now = std::chrono::steady_clock::now();
    auto elapsed_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_fps_log_time_);

    if (elapsed_milliseconds.count() >= 1000) { // 每秒打印一次
        // 使用 metaObject()->className() 可以动态获取派生类的名称，方便调试
        qDebug() << "[" << (this->metaObject() ? this->metaObject()->className() : "VideoCaptureBase")
                 << " DEBUG] Captured FPS:" << current_fps_count_.load();
        current_fps_count_ = 0;
        last_fps_log_time_ = now;
    }
}
